$(function() {
	var dg = $('#user_list');
	var total = 0;
    var pageSize = 20;
    var pageNum = 1;
	dg.datagrid({
		//title:'应用管理',
		url:contextPath+'/console/user/listByPageForEasyui?pageNo=1&pageSize='+pageSize,
		loadMsg: '加载中...',
		width: '100%',
        height: $("#user_list_div").height(),
        fitColumns:true,
		pagination:true,
        pageSize:pageSize,
        pageList:[5,10,20,40,80],
        singleSelect:true,
        selectOnCheck:false,
        checkOnSelect:false,
        rownumbers:true,
        toolbar: [{
            id:"easyuiAddBtn",
        	iconCls: 'icon-add',
        	text: '新增',
        	handler: function() {
        		appInfoDialog.openAdd();
        	}
        },{
            id:"easyuiUptBtn",
        	iconCls: 'icon-edit',
        	text: '修改',
        	handler: function() {
        		var app = dg.datagrid('getSelected');
                if(app.usertype=="0"){
                    return ;
                }
				appInfoDialog.openUpdate(app);
        	}
        },{
            id:"easyuiDelBtn",
        	iconCls: 'icon-remove',
        	text: '删除',
        	handler: function() {
        		var user = dg.datagrid('getSelected');
				if (!user) {
					apexLayer.Error('请先选择一条记录，才能进行删除操作！',null,false,1000);
					return;
				}
				apexLayer.Confirm('确定要删除？', '提示信息', null, null, function() {
					var url = contextPath+'/console/user/del?id=' + user.id;
					$.get(
						url,
						{},
						function (data) {
							if (data.success) {
								apexLayer.Msg("删除成功",500,function(){
									self.window.location = contextPath+"/console/user/list";
								});
							} else {
								apexLayer.Error(data.note,null,false,1000);
							}
						},
						'json'
					);
				}, null);
        	}
        },
		{
            id:"easyuiMenuAuthBtn",
			iconCls: 'icon-edit',
			text: '菜单权限修改',
			handler: function() {
				var app = dg.datagrid('getSelected');
				console.log(app);
                if(app.usertype=="0"){
                    return ;
                }
				appInfoDialog.openMenuUpdate(app);
			}
		}],
        columns:[[
			{field: 'loginId', title: '登陆ID',width: 100, halign:'center',align:'center'},
			{field: 'name', title: '用户名', width: 350,halign:'center',align:'center'},
            {field: 'attr', title: '读写属性',width: 100, halign:'center',align:'center',
				formatter: function(value,row,index){
					var val = JSON.parse(value);
					if (val.editable == 1){
						return '读写';
					} else {
						return '只读';
					}
				}
			}
        ]],
        onLoadSuccess:function (data) {
            total = dg.datagrid('getData').total;
            var pager = dg.datagrid('getPager');
            pager.pagination({
                onSelectPage: function (pageNumber, size) {
                    pageSize = size;
                    pageNum = pageNumber == 0 ?1:pageNumber;
                    var url = contextPath+'/console/user/listByPageForEasyui?pageSize='+size+'&pageNo='+pageNum;
                    $.get(
                    	url,
                        {},
                        function (data) {
                            dg.datagrid('loadData', data);
                        },
                        'json'
                    );

                }
            });

            //判断运维用户是否有读写权限，开关工具栏功能按钮
            toolbarSwitch();
        }
    });
});
